package org.dromara.pe.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.pe.domain.bo.DeviceScoreRawBo;
import org.dromara.pe.domain.vo.DeviceScoreRawVo;
import org.dromara.pe.service.IDeviceScoreRawService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.pe.domain.vo.DataAcquisitionVo;
import org.dromara.pe.domain.bo.DataAcquisitionBo;
import org.dromara.pe.service.IDataAcquisitionService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 数据采集记录
 *
 * @author Lion Li
 * @date 2024-09-02
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/pe/dataAcquisition")
public class DataAcquisitionController extends BaseController {

    private final IDataAcquisitionService dataAcquisitionService;

    /**
     * 查询数据采集记录列表
     */
    @SaCheckPermission("pe:dataAcquisition:list")
    @GetMapping("/list")
    public TableDataInfo<DataAcquisitionVo> list(DataAcquisitionBo bo, PageQuery pageQuery) {
        return dataAcquisitionService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出数据采集记录列表
     */
    @SaCheckPermission("pe:dataAcquisition:export")
    @Log(title = "数据采集记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(DataAcquisitionBo bo, HttpServletResponse response) {
        List<DataAcquisitionVo> list = dataAcquisitionService.queryList(bo);
        ExcelUtil.exportExcel(list, "数据采集记录", DataAcquisitionVo.class, response);
    }

    /**
     * 获取数据采集记录详细信息
     *
     * @param acquisitionId 主键
     */
    @SaCheckPermission("pe:dataAcquisition:query")
    @GetMapping("/{acquisitionId}")
    public R<DataAcquisitionVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long acquisitionId) {
        return R.ok(dataAcquisitionService.queryById(acquisitionId));
    }

    /**
     * 新增数据采集记录
     */
    @SaCheckPermission("pe:dataAcquisition:add")
    @Log(title = "数据采集记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody DataAcquisitionBo bo) {
        return toAjax(dataAcquisitionService.insertByBo(bo));
    }

    /**
     * 修改数据采集记录
     */
    @SaCheckPermission("pe:dataAcquisition:edit")
    @Log(title = "数据采集记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody DataAcquisitionBo bo) {
        return toAjax(dataAcquisitionService.updateByBo(bo));
    }

    /**
     * 删除数据采集记录
     *
     * @param acquisitionIds 主键串
     */
    @SaCheckPermission("pe:dataAcquisition:remove")
    @Log(title = "数据采集记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{acquisitionIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] acquisitionIds) {
        return toAjax(dataAcquisitionService.deleteWithValidByIds(List.of(acquisitionIds), true));
    }
}
